package com.review.Test.Provider_Consumer;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.atomic.AtomicInteger;

public class Provider implements Runnable{
	
	private LinkedBlockingQueue<Data> queue;
	private static AtomicInteger i = new AtomicInteger();
	private volatile boolean isRun = true;
	
	public Provider(LinkedBlockingQueue<Data> queue) {
		super();
		this.queue = queue;
	}

	@Override
	public void run() {
		while (isRun) {
			int num = i.incrementAndGet();
			Data data = new Data(num, "data"+num);
			try {
				Thread.sleep(500);
				this.queue.put(data);
				System.out.println("入队：  " + data);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		
	}
	
	public void stop(){
		this.isRun = false;
	}
	
}
